<?php
namespace app\controller\api\v1\repair;

use app\model\order\StoreOrder;
use app\model\other\CityArea;
use app\model\v1\repair\RepairCat;
use app\model\v1\repair\RepairCatUser;
use app\services\message\service\StoreServiceRecordServices;
use app\services\message\SystemMessageServices;
use app\services\order\StoreOrderRefundServices;
use app\services\order\StoreOrderServices;
use app\services\user\UserAuthServices;
use crmeb\services\wechat\OfficialAccount;
use app\Request;
use app\services\order\StoreOrderCreateServices;
use app\services\user\UserAddressServices;
use dh2y\qrcode;
use think\facade\Db;

/**
 * Class Store
 * @package app\controller\api\v1\store
 */
class Order
{
	//获取维修项目
	public function get_two_cat(Request $request)
	{
		$id = $param["id"] ?? 0;
//		$name= $request->getMore([
//			['name','装修项目']
//		]);
		$data = RepairCat::getApiRepairCatData($id, '');

		return app('json')->successful('ok',$data);
	}
	/**
	 * 第三方厂商维修工列表
	 * @param Request $request
	 * @return \think\Response
	 */
	public function getRepairCatUserData(Request $request)
	{
		$param = $request->param();

		$param['user_id'] = $request->uid();
		try {
			$data = RepairCatUser::getRepairCatUserData($param);

			return app('json')->success($data);
		} catch (\Throwable $e) {
			return app('json')->fail($e->getMessage());
		}
	}

	//获取维修工种
	public function wokr_type_cat ()
	{
		$data = Db::name ('work_type')->where ('status',1)->where ('pid',0)->field ('id,name')->select ()->toArray ();

		foreach ($data as &$v){
			$v['data'] = Db::name ('work_type')->where ('status',1)->where ('pid',$v['id'])->field ('id,name,fixed')->select ()->toArray ();
		}
		return app('json')->successful('ok',$data);
	}
	/**
	 * 创建维修订单
	 * @param Request $request
	 * @return mixed
	 */
	public function repair_create (Request $request, StoreOrderCreateServices $createServices)
	{
		$uid =  $request->uid();
		$data =[$addressId,$title,$files,$mp3,$describe,$time,$type] = $request->postMore([
			[['addressId', ''], 0],
			['title', ''],
			['files', ''],
			['mp3', ''],
			['describe', ''],
			['time', ''],
			['type', 1],
		], true);
		$product_type = 0;
		//普通商品 验证地址
		if (!$addressId) {
			return app('json')->fail('请选择收货地址!');
		}

		/** @var UserAddressServices $addressServices */
		$addressServices = app()->make(UserAddressServices::class);
		if (!$addressInfo = $addressServices->getOne(['uid' => $uid, 'id' => $addressId, 'is_del' => 0])){
			return app('json')->fail('地址选择有误!');
		}
		$addressInfo = $addressInfo->toArray();

		try {
			$msg = '';
			$order = $createServices->createOrder_weixiu($uid,$addressId,$addressInfo,$title,$files,$mp3,$describe,$time,$type,'');

		} catch (\Throwable $e) {
			$order = false;
			$msg = $e->getMessage();
			\think\facade\Log::error('订单生成失败，原因：' . $msg . $e->getFile() . $e->getLine());
			if ($order === false) {
				return app('json')->fail($msg ?: '订单生成失败');
			}
		}

		$orderId = $order['order_id'];
		return app('json')->status('success', '订单创建成功', ['order_id' => $orderId]);
	}
	/**
	 * 创建质保订单
	 * @param Request $request
	 * @return mixed
	 */
	public function repair_assurance_create (Request $request, StoreOrderCreateServices $createServices)
	{
		$uid =  $request->uid();
		[$title,$files,$mp3,$describe,$time,$type,$addressInfo,$order_id,$cat_id,$construction_id,$userAddress,$userLocation] = $request->postMore([
			['title', ''],
			['files', ''],
			['mp3', ''],
			['describe', ''],
			['time', ''],
			['type', 1],
			['addressInfo', ''],
			['order_id', ''],
			['cat_id', ''],
			['construction_id', ''],
			['userAddress', ''],
			['userLocation', ''],
		], true);
		$product_type = 0;
		//普通商品 验证地址
		$addressId=input ('addressId',0);
		$addressInfo = json_decode($addressInfo, true);
		$order = Db::name('store_order')->where ('id',$order_id)->where ('is_zhibao',2)->find();
		if ($order){
			return app('json')->fail( '此质保已有质保订单，请完成后进行在进行质保');
		}
		try {
			$msg = '';
			$order = $createServices->createOrder_weixiu($uid,$addressId,$addressInfo,$title,$files,$mp3,$describe,$time,$type,$order_id,$cat_id,$construction_id,$userAddress,$userLocation);

		} catch (\Throwable $e) {
			$order = false;
			$msg = $e->getMessage();
			\think\facade\Log::error('订单生成失败，原因：' . $msg . $e->getFile() . $e->getLine());
		}
		if ($order === false) {
			return app('json')->fail($msg ?: '订单生成失败');
		}
		$orderId = $order['order_id'];
		return app('json')->status('success', '订单创建成功', ['order_id' => $orderId]);
	}

	public function user_count (Request $request, StoreOrder $StoreOrder)
	{		$where = $request->postMore([
		['type', 99],//订单类型

	]);
		$where['uid'] = $request->uid();
		$where['is_system_del'] = 0;
		$count['repair'] =$StoreOrder->where (function ($query) use ($where) {
			if ($where['type']){
				$query->where('type', 99);
			}
			if ($where['uid']){
				$query->where('uid', $where['uid']);
			}
			if ($where['is_system_del']){
				$query->where('is_system_del', $where['is_system_del']);
			}
			$query->where('status', '<',3);
			$query->where('is_wenti', '<',2);
			$query->where('is_del', 0);
			$query->wherein('refund_status', [0, 3]);

		})->count();
		$count['repair_ok'] =$StoreOrder->where (function ($query) use ($where) {
			if ($where['type']){
				$query->where('type', 99);
			}
			if ($where['uid']){
				$query->where('uid', $where['uid']);
			}
			if ($where['is_system_del']){
				$query->where('is_system_del', $where['is_system_del']);
			}
			$query->where('status', '=',3);
			$query->where('is_wenti', '=',2);
			$query->where('is_del', 0);
		})->whereOr (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('is_del', 1);
			$query->where('refund_status', 2);
			$query->where('is_system_del', 0);
		})->count();
		return app('json')->successful('ok',$count);

	}

	/**
	 * 用户 -----------正在维修订单列表
	 * @param Request $request
	 * @return mixed
	 */
	public function user_repair_list (Request $request, StoreOrder $StoreOrder)
	{
		$where = $request->postMore([
			['type', 99],//订单类型

		]);

		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$where['uid'] = $request->uid();

		$field = ['*'];
		$list =$StoreOrder->where (function ($query) use ($where) {
			if ($where['type']){
				$query->where('type', 99);
			}
			if ($where['uid']){
				$query->where('uid', $where['uid']);
			}
			$query->where('status', '<',3);
			$query->where('is_wenti', '<',2);
			$query->where('is_del', 0);
			$query->where('is_system_del', 0);
			$query->wherein('refund_status', [0, 3]);
		})
			->page ($page,$limit)->field ($field)->with ('maintenance')->with ('maintenanceorder')->with ('maintenancewenti')->order (['id'=>'desc'])->select ()->toArray ();
		$count =$StoreOrder->where (function ($query) use ($where) {
			if ($where['type']){
				$query->where('type', 99);
			}
			if ($where['uid']){
				$query->where('uid', $where['uid']);
			}
			$query->where('status', '<',3);
			$query->where('is_wenti', '<',2);
			$query->where('is_system_del', 0);
			$query->wherein('refund_status', [0, 3]);
			$query->where('is_del', 0);
		})->count();
		$list = $this->chuli($list);

		return app('json')->successful('ok',compact('count', 'list'));
	}

	public function announcement_list (Request $request,StoreOrder $StoreOrder)
	{
		$where = $request->postMore([
			['type', 99],//订单类型

		]);

		$where['uid'] = $request->uid();
		$where['is_system_del'] = 0;

		$list =$StoreOrder->where (function ($query) use ($where) {
			if ($where['type']){
				$query->where('type', 99);
			}
			if ($where['uid']){
				$query->where('uid', $where['uid']);
			}
			if ($where['is_system_del']){
				$query->where('is_system_del', $where['is_system_del']);
			}
			$query->where('status', '<',3);
			$query->where('is_wenti', '<',2);
			$query->where('is_del', 0);
		})->order('id','desc')
			->select ()->toArray ();
		$lists =array ();
		$lists['re'] =0;
		$lists['res'] =0;
		$lists['ress'] =0;
		foreach ($list as $k => &$v) {
			if ($v['paid'] == 0) {
				if ($v['weixiu_status'] === 1) {
					$lists['re'] =1;

				}elseif ($v['weixiu_status'] === 2) {
					$lists['res'] +=1;
				}
			}

			if ($v['status'] === 2 && $v['paid'] === 1 && $v['is_shangmen'] == 2&& $v['is_wenti'] == 0) {
				$lists['ress']+=1;
			}
		}
		return app('json')->successful('ok',$lists);
	}
	/**
	 * 用户 -------------------用户完成维修订单包括取消的
	 * @param Request $request
	 * @return mixed
	 */
	public function user_repair_list_ok (Request $request, StoreOrder $StoreOrder)
	{
		$where = $request->postMore([
			['type', 99],//订单类型
			['uid', ''],//订单类型
		]);

		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$where['is_system_del'] = 0;

		$field = ['*'];
		$list =$StoreOrder->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('uid', $where['uid']);
			$query->where('is_system_del', 0);
			$query->where('status', '>=',2);
			$query->where('is_wenti', '=',2);
		})->whereOr (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('uid', $where['uid']);
			$query->where('is_del', 1);
		})->whereOr (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('uid', $where['uid']);
			$query->where('refund_status', 2);
		})
			->page ($page,$limit)->field ($field)->with ('maintenance')->with ('maintenanceorder')->with ('maintenance_wenti')->order ('wenti_time','desc')->select ()->toArray ();
		$count =$StoreOrder->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('uid', $where['uid']);
			$query->where('is_system_del', 0);
			$query->where('status', '>=',2);
			$query->where('is_wenti', '=',2);
		})->whereOr (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('uid', $where['uid']);
			$query->where('is_del', 1);
		})->whereOr (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('uid', $where['uid']);
			$query->where('refund_status', 2);
		})->count();
		$list = $this->chuli($list);

		return app('json')->successful('ok',compact('count', 'list'));
	}
	//维修取消订单
	public  function cancel_order (Request $request, StoreOrder $StoreOrder,StoreOrderRefundServices $services, StoreOrderServices $orderServices)
	{
		$order_id= $request->post ('order_id');
		$order = $StoreOrder->where ('order_id', $order_id)->find ();
		if ($order['paid']==0){
			$StoreOrder->where ('order_id', $order_id)->update(['is_del'=>1]);
		}
		elseif  ($order['paid']==1){
			$id = $order['id'];
			//主动退款
			$data['refund_price'] = sprintf("%.2f", $order['pay_price']);
			if (!$order) {
				return $this->fail('Data does not exist!');
			}
			if ($services->count(['store_order_id' => $id, 'refund_type' => [0, 1, 2, 4, 5], 'is_cancel' => 0, 'is_del' => 1])) {
				return $this->fail('请先处理售后申请');
			}
			//0元退款
			if ($order['pay_price'] == 0 && in_array($order['refund_status'], [0, 1])) {
				$refund_price = 0;
			} else {
				if ($order['pay_price'] == $order['refund_price']) {
					return $this->fail('已退完支付金额!不能再退款了');
				}
				if (!$data['refund_price']) {
					return $this->fail('请输入退款金额');
				}
				$refund_price = $data['refund_price'];
				$data['refund_price'] = bcadd($data['refund_price'], $order['refund_price'], 2);
				$bj = bccomp((string)$order['pay_price'], (string)$data['refund_price'], 2);
				if ($bj < 0) {
					return $this->fail('退款金额大于支付金额，请修改退款金额');
				}
			}
				$data['refund_status'] = 2;
				$data['refund_type'] = 6;
				$data['is_del'] = 1;


				$refund_data['pay_price'] = $order['pay_price'];
				$refund_data['refund_price'] = $refund_price;
				if ($order['refund_price'] > 0) {
					mt_srand();
					$refund_data['refund_id'] = $order['order_id'] . rand(100, 999);
				}
				$refundId = $services->splitApplyRefund((int)$id, $order, [], $data['refund_type'], $refund_price, $data);
				//修改订单退款状态
				if ($services->agreeRefund($refundId, $refund_data)) {
					//主动退款清楚原本退款单
					$services->delete(['store_order_id' => $id]);
					if (0) {
						$services->update($refundId, $data);
					} else {
						$orderServices->update($id, $data);
					}
					return app('json')->success('退款成功');
				} else {
					$services->storeProductOrderRefundYFasle((int)$id, $refund_price);
					return app('json')->fail('退款失败');
				}
		}

		if($order['type'] == 99&&$order['maintenance_type']==2){
			$StoreOrder->where ('id', $order['pid'])->update(['is_zhibao' =>1]);
		}

		return app('json')->successful('取消成功');

	}

	public function user_repair_index (Request $request, StoreOrder $StoreOrder)
	{
		$where = $request->postMore([
			['order_id', ''],//订单类型

		]);
		$where['is_system_del'] = 0;

		$field = ['*'];
		$data =$StoreOrder->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('is_system_del',0);
			if ($where['order_id']){    //正在维修的订单
				$query->where('order_id|id',$where['order_id']);
			}
		})
			->field ($field)->with (['maintenance_wenti','maintenance','maintenanceorder'])->select()->toArray ();
		$index = $this->chuli_index ($data);


		return app('json')->successful('ok',$index);
	}

	public function maintenance_order (Request $request)
	{
		$order_id= $request->postMore([
			['order_id','']
		]);
		$orders = Db::name('store_order')->where ('id|order_id',$order_id['order_id'])->field ('order_id')->find ();

		$order =Db::name('maintenance_order')->alias ('m')->where ('m.order_id', $orders['order_id'])->where ('m.status',5)->join ('repair_service r','r.uid = m.maintenance_user_id')->select()->toArray ();
		return app('json')->successful('ok',$order);
		//1
	}
	//处理数据
	public function chuli_index ($data)
	{
		$StoreOrder = new StoreOrder;

		foreach ($data as &$v){
			if ($v['is_del']==1){
				$v['_title']='订单已取消';
			}else{
				if ($v['paid'] == 0) {
					if ($v['weixiu_status'] === 1) {
						$v['_title']='我们尽快与您取得联系 请您耐心等待报价';
					}elseif ($v['weixiu_status'] === 2) {
						$v['_title']='报价结果已出 请前往支付';
					}
				}
				if ($v['status'] === 0 && $v['paid'] === 1) {
					$v['_title']='等待维修师傅接单';
				}
				if ($v['status'] === 1 && $v['paid'] === 1 &&$v['is_shangmen']==1) {
					$v['_title']='维修师傅已接单 正在火速赶来';
				}if ($v['status'] === 1 && $v['paid'] === 1&&$v['is_shangmen']==2) {
					$v['_title']='师傅正在维修中';
				}
				if ($v['status'] === 2 && $v['paid'] === 1 &&$v['is_shangmen']==2&& $v['is_wenti']==0) {
					$v['_title']='维修已完成 若维修有问题请整改提交';
				}if ($v['status'] === 1 && $v['paid'] === 1&&$v['is_shangmen']==2&& $v['is_wenti']==1) {
					$v['_title']='整改问题已提交 等待师傅上门维修';
				}
				if ($v['status'] === 3 && $v['paid'] === 1) {
					$v['_title']='交易完成';
				}
				if ($v['refund_status'] === 2 && $v['refund_type'] === 6) {
					$v['_title']='已退款';
				}
			}

            if ($v['survey_user_id_2']==$v['survey_user_id']){
                $v['survey_user_id_2_data'] = [];
            }elseif ($v['survey_user_id_2']!=$v['survey_user_id']&&$v['survey_user_id_2']!=''){
                $v['survey_user_id_2_data'] = Db::name('repair_service')->where('uid',$v['survey_user_id_2'] )->find();
            }
            foreach ($v['maintenanceorder'] as $k => &$vv) {

				$vv['data'] = Db::name('repair_service')->where('uid', $vv['maintenance_user_id'])->find();
			}

			if ($v['paid'] == 0) {
				if ($v['weixiu_status'] === 1) {
					if ($v['is_send']==1&&$v['status']==-1){
						if (date('Y-m-d H:i:s', (time()+1800))>=$v['time']  && date('Y-m-d H:i:s')<$v['time']){
							$v['sur_time']=(strtotime($v['time'])-time())/60 >=30?'30':(strtotime($v['time'])-time())/60;
							$v['sur_title']='待报价';

						}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['time']  && date('Y-m-d H:i:s')>$v['time']){
							$v['sur_time']=(time()-strtotime( $v['time']))/60>=1?(time()-strtotime( $v['time']))/60:'1'; //待报价超时倒计时
							$v['sur_title']='已超时';   //已超时
							if ($v['is_quote']!=2){
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_quote'=>2]);
								$data['order_id']= $v['order_id'];
								$data['fine']= 10;
								$data['work_category']= 1;
								$data['uid']=$v['survey_user_id'];
								$data['name']= '报价超时';
								$data['duration']= $v['sur_time'];
								$this->add_violati($data);
							}
						}
					}
					if ($v['is_survey_shangmen']==1&&$v['survey_user_id_2']>0&&$v['is_send']==2){
						if (date('Y-m-d H:i:s', (time()+1800))>=$v['time']  && date('Y-m-d H:i:s')<$v['time']){

							$v['sur_time']=(strtotime($v['time'])-time())/60 >=30?'30':(strtotime($v['time'])-time())/60;
							$v['sur_title']='待上门';

						}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['time']  &&  date('Y-m-d H:i:s')>$v['time']){
							$v['sur_time']=(time()-strtotime( $v['time']))/60>=1?(time()-strtotime( $v['time']))/60:'1'; //上门超时倒计时
							$v['sur_title']='已超时';
							if ($v['is_timeout_survey_shangmen']!=2){
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_timeout_survey_shangmen'=>2]);
								$data['order_id']= $v['order_id'];
								$data['fine']= 10;
								$data['work_category']= 1;
								$data['uid']=$v['survey_user_id_2'];
								$data['name']= '上门超时';
								$data['duration']=$v['sur_time'];
								$this->add_violati($data);

							}
						}
					}elseif($v['is_survey_shangmen']==2&&$v['survey_user_id_2']!=null&&$v['is_send']==2&&$v['is_timeout_survey']==1){
						if ($v['is_timeout_survey_shangmen']==2){
							$times = strtotime ($v['times'])+(strtotime ($v['shangmen_time'])-strtotime ($v['time']));

							if (date('Y-m-d H:i:s', (time()+1800))>=$times&&time()<$times){
								$timessss=((time()+1800)-strtotime($times))/60;

								$v['sur_time']=$timessss>=1?$timessss:'1';  //勘察倒计时
								$v['sur_title']='勘察时长';  //勘察倒计时
							}elseif(date('Y-m-d H:i:s', (time()+1800))>=$times&& date('Y-m-d H:i:s')>$times){

								$v['sur_time']=strtotime( time()-$times)/60>=1?strtotime( time()-$times)/60:'1';//勘察超时正计时
								$v['sur_title']='已超时';  //勘察倒计时
								if ($v['is_timeout_survey']!=2){
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_timeout_survey'=>2]);
									$data['order_id']= $v['order_id'];
									$data['fine']= 10;
                                    $status = Db::name('repair_service')->where ('uid', $v['is_repair_survey'])->where ('status',1)->find();
                                    if ($status){
                                        $data['work_category']= 2;
                                    }else{
                                        $data['work_category']= 1;
                                    }									$data['uid']=$v['survey_user_id_2'];
									$data['name']= '勘察超时';
									$data['duration']= $v['sur_time'];
									$this->add_violati($data);
								}

							}
						}else{
							if (date('Y-m-d H:i:s', (time()+1800))>=$v['times']  &&  date('Y-m-d H:i:s')<$v['times']){

								$v['sur_time']=(strtotime($v['time'])-time())/60 >=30?'30':(strtotime($v['time'])-time())/60;

								$v['sur_title']='勘察时长';  //勘察倒计时

							}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['times']  &&  date('Y-m-d H:i:s')>$v['times']){
								$v['sur_time']=(time()-strtotime( $v['time']))/60>=1?(time()-strtotime( $v['time']))/60:'1'; //勘察超时正计时
								$v['sur_title']='已超时';  //勘察倒计时
								if ($v['is_timeout_survey']!=2){
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_timeout_survey'=>2]);
									$data['order_id']= $v['order_id'];
									$data['fine']= 10;
                                   $status = Db::name('repair_service')->where ('uid', $v['is_repair_survey'])->where ('status',1)->find();
                                   if ($status){
                                       $data['work_category']= 2;
                                   }else{
                                       $data['work_category']= 1;
                                   }
									$data['uid']=$v['survey_user_id_2'];
									$data['name']= '勘察超时';
									$data['duration']= $v['sur_time'];
									$this->add_violati($data);
								}
							}
						}
					}

				}
			}
			if (isset($v['sur_time'])){
				$v['sur_time']=floor($v['sur_time']);
			}
		}
		return $data ;
	}	//处理数据
	public function chuli ($list)
	{
		foreach ($list as $k => &$v) {
			if ($v['paid'] == 0) {
				if ($v['weixiu_status'] === 1) {
					$v['_title']='待报价';
					$v['_status']='1';
					if ($v['is_survey_shangmen']==1&&$v['survey_user_id_2']!=null){
						date('Y-H-i');
						if ($v['time'])
							$v['sur_time']='';
					}

				}elseif ($v['weixiu_status'] === 2) {
					$v['_title']='待支付';
					$v['_status']='2';
					$v['_time']='300';

				}
			}
			if ($v['status'] === 0 && $v['paid'] === 1) {
				$v['_title']='维修工待接单';
				$v['_status']='3';

			}
			if ($v['status'] === 1 && $v['paid'] === 1 && $v['is_shangmen'] == 1) {
				$v['_title']='维修工待上门';
				$v['_status']='4';

			}
			if ($v['status'] === 1 && $v['paid'] === 1 && $v['is_shangmen'] == 2&& $v['is_wenti'] != 1) {
				$v['_title']='维修中';
				$v['_status']='5';

			}
			if ($v['status'] === 2 && $v['paid'] === 1 && $v['is_shangmen'] == 2&& $v['is_wenti'] != 1) {
				$v['_title']='待验收';
				$v['_status']='6';

			}
			if ($v['status'] === 1 && $v['paid'] === 1 && $v['is_shangmen'] == 2&& $v['is_wenti'] == 1) {
				$v['_title']='整改中';
				$v['_status']='7';

			}
			if ($v['status'] === 2 && $v['paid'] === 1 && $v['is_shangmen'] == 2&& $v['is_wenti'] == 2) {
				$v['_title']='带评价';
				$v['_status']='8';

			}
			if ($v['status'] === 3 && $v['paid'] === 1) {
				$v['_title']='交易完成';
				$v['_status']='9';

			}
			if ($v['is_del'] === 1) {
				$v['_title']='订单取消';
				$v['_status']='10';

			}
		}
		return $list ;
	}

	//处理快修首页提示信息
	public function  title_chuli(Request $request, StoreOrder $StoreOrder)
	{
		$where = $request->postMore([
			['type', 99],//订单类型
			['status', '1'],//订单状态

		]);

		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$where['uid'] = $request->uid();
		$where['is_del'] = 0;
		$where['is_system_del'] = 0;
		$field = ['*'];
		$title=[];
		$list =$StoreOrder->where (function ($query) use ($where) {
			if ($where['type']){
				$query->where('type', 99);
			}
			if ($where['uid']){
				$query->where('uid', $where['uid']);
			}
			if ($where['is_del']){
				$query->where('is_del', $where['is_del']);
			}
			if ($where['is_system_del']){
				$query->where('is_system_del', $where['is_system_del']);
			}
			if ($where['status']==1){    //正在维修的订单
				$query->where('status', '<',3);
				$query->where('is_wenti', '<',2);
			}
		})
			->page ($page,$limit)->field ($field)->with ('maintenance')->with ('maintenance_wenti')->select ()->toArray ();
		$title['weixiu_status']=0;
		$title['pay_status']=0;
		$title['yanshou_status']=0;
		foreach ($list as $k => &$v) {
			if ($v['paid'] === 0) {
				if ($v['weixiu_status'] === 1) {
					$title['weixiu_status']+=1;
				}elseif ($v['weixiu_status'] === 2) {
					$title['pay_status']+=1;
				}
			}
			if ($v['status'] === 2 && $v['is_wenti'] === 0 && $v['is_call']) {
				$title['yanshou_status']+=1;
			}
		}
		return app('json')->successful('ok',$title);
	}

	//维修工////维修工/////维修工/////维修工//////维修工/////维修工

	//退单
	public function chargeback (Request $request, StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$title = input ('title');
		$status = input ('status');

			$StoreOrder->where ('order_id',$order_id)->update(['is_chargeback'=>2,'chargeback_title'=>$title]);
		if ($status==1){
			$StoreOrder->where ('order_id',$order_id)->update(['survey_user_id_2'=>'','is_send'=>1]);
		}else{
			$StoreOrder->where ('order_id',$order_id)->update(['survey_user_id_2'=>'','is_send'=>1]);
			Db::name('maintenance_order')->where ('order_id',$order_id)->delete ();
		}
		$data['order_id']= $order_id;
		$data['fine']= 50;
		$data['work_category']= 2;
		$data['uid']= $request->uid ();
		$data['name']= '退单违规';
		$this->add_violati($data);
		return app('json')->successful('ok');
	}
	//接单维修工
	public function user_repair_receive (Request $request, StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$uid=$request->uid ();
		$order =$StoreOrder->where ('order_id', $order_id)->find ();
		if ($order['paid']!=1){
			return app('json')->fail( '此订单未支付');
		}
		Db::name('maintenance_order')->where ('order_id', $order_id)->where ('maintenance_user_id', $uid)->update(['status' =>2]);
		$StoreOrder->where ('order_id', $order_id)->update(['status' =>1]);

		return app('json')->successful('ok');
	}
	// 维修工上门
	public function user_repair_call (Request $request, StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$img = input ('img');
		$uid=$request->uid ();
		$order =$StoreOrder->where ('order_id', $order_id)->find ();
		$maintenance_order = Db::name('maintenance_order')->where ('order_id', $order_id)->where ('maintenance_user_id', $uid)->find ();

		if ($order['paid']!=1){
			return app('json')->fail( '此订单未支付');
		}
		if ($maintenance_order['status']!=2){
			return app('json')->fail( '此订单不是接单状态');
		}
		$date=	date('Y-m-d H:i:s');
		Db::name('maintenance_order')->where ('order_id', $order_id)->where ('maintenance_user_id', $uid)->update(['img' =>$img,'status' =>3,'shangmentime'=>$date]);

		$StoreOrder->where ('order_id', $order_id)->update(['is_shangmen' =>2]);

		return app('json')->successful(['date'=>$date]);
	}
	//接单 维修工完成
	public function user_repair_ok (Request $request, StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$img= input ('img');
		$uid=$request->uid ();
		$maintenance_tishi= input ('maintenance_tishi');
		$order =$StoreOrder->where ('order_id', $order_id)->find ();
		if ($order['paid']!=1){
			return app('json')->fail( '此订单未支付');
		}
		if ($order['is_shangmen']!=2){
			return app('json')->fail( '此订单还没有上门');
		}
		if ($order['is_del']==1){
			return app('json')->fail( '此订单还已取消');
		}

		if ($order['refund_status']==2&&$order['refund_type']==6){
			return app('json')->fail( '此订单已退款');
		}
		$StoreOrder->where ('order_id', $order_id)->update(['status' =>2,'is_wenti'=>0]);

		Db::name('maintenance_order')->where ('order_id', $order_id)->where ('maintenance_user_id', $uid)->update(['status' =>4,'ok_time'=>date('Y-m-d H:i:s')]);

		Db::name('maintenance')->where('order_id',$order_id)->update(['files_user_maintenance'=>$img,'time_maintenance'=>date ('Y-m-d H:i:s'),'maintenance_tishi'=>$maintenance_tishi]);
		return app('json')->successful('ok');
	}
	//维修工 列表
	public function user_maintenance_list (Request $request, StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$where = $request->postMore([
			['status', 1],//订单状态
		]);

		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$where['is_del'] = 0;
		$where['type'] = 99;
		$where['uid']= $request->uid ();
		$field = ['id', 'type', 'pid', 'order_id', 'uid', 'spread_uid', 'pink_id', 'store_id', 'supplier_id', 'shipping_type', 'delivery_type', 'paid', 'pay_type', 'pay_price', 'pay_integral', 'total_num', 'add_time', 'pay_time', 'status', 'refund_status', 'title', 'files', 'mp3','m.status as mstatus,c*'];
		$where['is_system_del'] = 0;
		if ($where['status']!=2){
			$list =Db::name('maintenance_order')->alias ('m')->leftjoin ('store_order o','o.order_id = m.order_id')->join ('maintenance c','o.order_id = c.order_id')->where (function ($query) use ($where) {
				$query->where('type', 99);
				$query->where('o.is_system_del', $where['is_system_del']);
				$query->where('o.is_del', $where['is_system_del']);

				if ($where['status']==1){    //已支付  待接单
					$query->where('o.paid', 1);
					$query->where('m.maintenance_user_id',$where['uid']);
					$query->where('m.status', 1);
				}
				if ($where['status']==3){    //已支付
					$query->where('o.paid', 1);
					$query->where('maintenance_user_id',$where['uid']);
					$query->where('m.status', '<',5);
					$query->where('m.status', '>',1);
				}
				if ($where['status']==4){    //有问题
					$query->where('o.paid', 1);
					$query->where('maintenance_user_id',$where['uid']);
					$query->where('m.status', 6);
					$query->where('o.paid', 1);
				}
				if ($where['status']==5){    //記錄

					$query->where('maintenance_user_id',$where['uid']);
					$query->where('m.status', 5);
				}
			})->page ($page,$limit)->field ('o.*,m.*,c.*,m.status as mstatus,m.img as maintenance_img,m.shangmen_time as mshangmen_time')->order ('is_wenti DESC,is_zhibao DESC')->group ('m.order_id')->select ()->toArray ();

			$count	=Db::name('maintenance_order')->alias ('m')->leftjoin ('store_order o','o.order_id = m.order_id')->join ('maintenance c','o.order_id = c.order_id')->where (function ($query) use ($where) {
				$query->where('type', 99);
				$query->where('o.is_system_del', $where['is_system_del']);
				$query->where('o.is_del', $where['is_system_del']);

				if ($where['status']==1){    //已支付  待接单
					$query->where('o.paid', 1);
					$query->where('m.maintenance_user_id',$where['uid']);
					$query->where('m.status', 1);
				}
				if ($where['status']==3){    //已支付
					$query->where('o.paid', 1);
					$query->where('maintenance_user_id',$where['uid']);
					$query->where('m.status', '<',5);
					$query->where('m.status', '>',1);
				}
				if ($where['status']==4){    //有问题
					$query->where('o.paid', 1);
					$query->where('maintenance_user_id',$where['uid']);
					$query->where('m.status', 6);
					$query->where('o.paid', 1);
				}
				if ($where['status']==5){    //記錄

					$query->where('maintenance_user_id',$where['uid']);
					$query->where('m.status', 5);
				}
			})->order ('is_wenti DESC,is_zhibao DESC')->group ('m.order_id')->count();
			$list = $this->chuli2($list);

			return app('json')->successful('ok',compact('count', 'list'));
		}else{
			$list =$StoreOrder->where (function ($query) use ($where) {
				$query->where('type', 99);
				$query->where('is_system_del',0);
				if ($where['status']== 2){//勘查单
					$query->where('is_send',2);
					$query->where('survey_user_id_2',$where['uid']);
					$query->where('paid',0);
					$query->where('is_del',0);
				}
			})->page ($page,$limit)->group ('order_id')->field ('*')->select ()->toArray ();
			$count =$StoreOrder->where (function ($query) use ($where) {
				$query->where('type', 99);
				$query->where('is_system_del',0);
				if ($where['status']== 2){//勘查单
					$query->where('is_send',2);
					$query->where('survey_user_id_2',$where['uid']);
					$query->where('paid',0);
					$query->where('is_del',0);
				}
			})->group ( 'order_id')->count();
			$list = $this->chuli1($list);

			return app('json')->successful('ok',compact('count', 'list'));
		}
	}
	public function user_maintenance_list_count (Request $request, StoreOrder $StoreOrder)
	{
		$where['is_del'] = 0;
		$where['uid'] = $request->uid ();
		$where['type'] = 99;

		$where['is_system_del'] = 0;
		$count1 =Db::name('maintenance_order')->alias ('m')->leftjoin ('store_order o','o.order_id = m.order_id')->join ('maintenance c','o.order_id = c.order_id')->where (function ($query) use ($where) {
			$query->where('o.paid', 1);
			$query->where('m.maintenance_user_id',$where['uid']);
			$query->where('m.status', 1);
			$query->where('type', 99);
			$query->where('o.is_system_del', $where['is_system_del']);
			$query->where('o.is_del', $where['is_system_del']);
		})->group ( 'm.order_id')->count ();


		$count2 =$StoreOrder->where (function ($query) use ($where) {
			$query->where('is_system_del',0);
			$query->where('type',99);
			$query->where('is_send',2);
			$query->where('survey_user_id_2',$where['uid']);
			$query->where('paid',0);
			$query->where('is_del',0);
		})->count();
		$count3  =Db::name('maintenance_order')->alias ('m')->leftjoin ('store_order o','o.order_id = m.order_id')->join ('maintenance c','o.order_id = c.order_id')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('o.is_system_del', $where['is_del']);
			$query->where('o.is_del', $where['is_del']);
			$query->where('o.paid', 1);
			$query->where('maintenance_user_id',$where['uid']);
			$query->where('m.status', '<',5);
			$query->where('m.status', '>',1);
		})->group ('m.order_id')->count ();

		$count4 =Db::name('maintenance_order')->alias ('m')->leftjoin ('store_order o','o.order_id = m.order_id')->join ('maintenance c','o.order_id = c.order_id')->where (function ($query) use ($where) {
			$query->where('o.is_system_del', $where['is_system_del']);
			$query->where('o.paid', 1);
			$query->where('maintenance_user_id',$where['uid']);
			$query->where('m.status', 6);
			$query->where('o.paid', 1);
			$query->where('is_del',0);
		})->count ();
		return app('json')->successful('ok',['count1'=>$count1,'count2'=>$count2,'count3'=>$count3,'count4'=>$count4]);

	}

	public function chuli4 ($list)
	{
		foreach ($list as $k => &$v) {
			if ($v['status']==0&&$v['is_shangmen']==1&&$v['is_wenti']==0){
				$v['_title_']='工人待接单';
			}
			if ($v['status']==1&&$v['is_shangmen']==1&&$v['is_wenti']==0){
				$v['_title_']='工人待上门';
			}
			if ($v['status']==1&&$v['is_shangmen']==2&&$v['is_wenti']==0){
				$v['_title_']='工人维修中';
			}
			if ($v['status']==2&&$v['is_shangmen']==2&&$v['is_wenti']==0){
				$v['_title_']='客户待验收';
			}
			if ($v['status']==1&&$v['is_shangmen']==2&&$v['is_wenti']==1){
				$v['_title_']='工人整改中';
			}
			if ($v['status']==2&&$v['is_shangmen']==2&&$v['is_wenti']==2){
				$v['_title_']='客户待验收';
			}
		}
		return $list ;
	}
	public function user_maintenance_list_ok (Request $request, StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$where = $request->postMore([
			['status', 1],//订单状态
		]);

		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$where['is_del'] = 0;
		$where['uid'] = $request->uid ();
		$where['type'] = 99;
		$field = ['id', 'type', 'pid', 'order_id', 'uid', 'spread_uid', 'pink_id', 'store_id', 'supplier_id', 'shipping_type', 'delivery_type', 'paid', 'pay_type', 'pay_price', 'pay_integral', 'total_num', 'add_time', 'pay_time', 'status', 'refund_status', 'title', 'files', 'mp3','m.status as mstatus'];
		$where['is_system_del'] = 0;
		$list =Db::name('maintenance_order')->alias ('m')->leftjoin ('store_order o','o.order_id = m.order_id')->join ('maintenance','maintenance.order_id = o.order_id')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('o.is_system_del', $where['is_system_del']);
			$query->where('maintenance_user_id',$where['uid']);
			$query->where('m.status', 5);
		})->page ($page,$limit)->field ('o.*,m.*,m.status as mstatus,m.img as maintenance_img,m.shangmen_time as mshangmen_time,maintenance.maintenance_content')->order ('o.wenti_time DESC')->select ()->toArray ();


		$count	=Db::name('maintenance_order')->alias ('m')->leftjoin ('store_order o','o.order_id=m.order_id')->where (function ($query) use    ($where) {
			$query->where('type', 99);
			$query->where('o.is_system_del', $where['is_system_del']);
			$query->where('maintenance_user_id',$where['uid']);
			$query->where('m.status', 5);
		})->count();
		$list = $this->chuli2($list);

		return app('json')->successful('ok',compact('count', 'list'));

	}
	public function user_list_time (Request $request, StoreOrder $StoreOrder)
	{
		$user = $request->postMore([
			['user_id', 0],//订单状态
		]);
		$data=Db::name('maintenance_order')
			->alias ('m')
			->join ('store_order o','o.order_id=m.order_id')
			->where ('m.maintenance_user_id',$user['user_id'])
			->where ('o.is_del',0)
			->where ('m.status','<>',5)
			->order ('m.service_times','desc')
			->field ('m.*')->select()->toArray ();

		return app('json')->success($data);

	}
	//用户提交问题整改
	public function add_maintenance_wenti (StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$title = input ('title');
		$mp3 = input ('mp3');
		$felis = input ('felis');
		Db ::name ('maintenance_wenti') -> insert (['title' => $title, 'mp3' => $mp3, 'felis' => $felis, 'ctime' => date ('Y-m-d H:i:s'), 'order_id' => $order_id]);
		$StoreOrder -> where ('order_id', $order_id) -> update (['is_wenti' => 1, 'status' => 1]);
		Db::name('maintenance')->where('order_id',$order_id)->update(['files_user_maintenance'=>'','time_maintenance'=>'','maintenance_tishi'=>'']);
		Db::name('maintenance_order')->where('order_id',$order_id)->where ('status',4)->update(['status'=>6]);

        $order =Db::name('maintenance_order')->where('order_id',$order_id)->select();
        foreach ($order as $oreder){
            $data=[];
            $data['order_id']= $order_id;
            $data['fine']= 10;
            $data['work_category']= 2;
            $data['uid']= $oreder['maintenance_user_id'];
            $data['name']= '整改问题';
            $this->add_violati($data);
        }

		return app('json')->successful('ok');

	}
	//用户确认验收
	public function maintenance_wenti_ok (StoreOrder $StoreOrder)
	{
		Db::startTrans();
		$order_id = input ('order_id');
		try{
				$order = $StoreOrder-> where ('order_id', $order_id)->find ();
				if ($order['refund_status']==2&&$order['refund_type']==6){
					return app('json')->fail( '此订单已退款无需确认验收');
				}
				$StoreOrder-> where ('order_id', $order_id) -> update (['is_wenti' => 2, 'status' => 2,'wenti_time'=>time()]);

				if ($order['maintenance_type']==2){
					$StoreOrder-> where ('id', $order['pid']) -> update (['is_zhibao' => 1]);
				}
				$date = date('Y-m', $order['add_time']);
				$dates = date('Y-m-d H:i:s', $order['add_time']);
				$dated = date('Y-m-d ', $order['add_time']);
				$maintenance =  Db::name('maintenance')->where ('order_id',$order_id)->find ();
				$status=0;
				$statuss=0;
				$tbj_Bad_prices=0;
				$performance = $maintenance['maintenance_price'];
				$tbj_ma_bili= Db::name ('config')->where ('key','tbj_ma_bili')->field ('value')->find ();
				$tbj_an_bili= Db::name ('config')->where ('key','tbj_an_bili')->field ('value')->find ();
				$maintenance_order = Db::name('maintenance_order')->where('order_id',$order_id)->where ('status','in',[3,4])->select ();

				if ($order['maintenance_type']!=2&&$performance>0){
					$maintenance_count  = count ($maintenance_order);
					$prices =round($performance*$tbj_ma_bili['value']/$maintenance_count,2);

					$data =[];
					foreach ($maintenance_order as $v){
						$data[] = ['time'=>$date,
							'user_id'=>$v['maintenance_user_id'],
							'single_quantity'=>1,
							'performance'=>$performance,
							'Bad'=>$status,
							'esteem'=>$statuss,
							'substract'=>$tbj_Bad_prices,
							'ticheng'=>$prices,
							'times'=>$dates,
							'timed'=>$dated,
							'order_id'=>$order_id];
					}
					Db::name('worker_examine')->insertAll($data);
					Db::name('worker_examine')->insert( ['time'=>$date,
						'user_id'=>$order['survey_user_id'],
						'single_quantity'=>1,
						'performance'=>$performance,
						'Bad'=>$status,
						'esteem'=>$statuss,
						'substract'=>$tbj_Bad_prices,
						'ticheng'=>round($performance*$tbj_an_bili['value'],2),
						'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
				//&&$performance>0
				}elseif ($order['maintenance_type']==2&&$performance>0){
					if ($order['pid']>0){
						$orders =$StoreOrder-> where ('id', $order['pid'])->field ('order_id') ->find ();
						$orderss =$StoreOrder-> where ('pid', $order['pid'])->where ('order_id','<>',$order_id) ->field ('order_id')->select ()->toArray ();
						if (!$orderss){
							$maintenance_user_id = Db::name('maintenance_order')->where ('order_id',$orders['order_id'])->where ('is_accomplish',2)->group ('maintenance_user_id')->select ()->toArray ();
							$maintenance_user_id = array_column($maintenance_user_id,'maintenance_user_id');
							$maintenance_user_ids = Db::name('maintenance_order')->where ('order_id',$order_id)->where ('status','in',[3,4])->group ('maintenance_user_id')->field ('maintenance_user_id')->select ()->toArray ();
							$maintenance_user_ids = array_column($maintenance_user_ids,'maintenance_user_id');

							$count=count($maintenance_user_id);
							$counts=count($maintenance_user_ids);
							$ticheng = Db::name('worker_examine')->where ('order_id',$orders['order_id'])->where ('user_id','in',$maintenance_user_id)->sum ('ticheng');
							$price = $ticheng/$count;   //6
							$prices = $ticheng/($count+$counts);  //2
							$price = $price - $prices;
							foreach ($maintenance_user_id as $v){
								Db::name('worker_examine')->insert( ['time'=>$date,
									'user_id'=>$v,
									'single_quantity'=>1,
									'performance'=>0,
									'Bad'=>$status,
									'esteem'=>$statuss,
									'substract'=>$price,
									'ticheng'=>0,
									'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
							}
							foreach ($maintenance_user_ids as $v){
								Db::name('worker_examine')->insert( ['time'=>$date,
									'user_id'=>$v,
									'single_quantity'=>1,
									'performance'=>$ticheng,
									'Bad'=>$status,
									'esteem'=>$statuss,
									'substract'=>0,
									'ticheng'=>$prices,
									'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
							}
						}else{
							$order_ids=array_column($orderss,'order_id');
							$order_ids[]=$orders['order_id'];

							$maintenance_user_id = Db::name('maintenance_order')->where ('order_id','in',$order_ids)->where ('is_accomplish',2)->group ('maintenance_user_id')->select ()->toArray ();
							$maintenance_user_id = array_column($maintenance_user_id,'maintenance_user_id');

							$maintenance_user_ids = Db::name('maintenance_order')->where ('order_id',$order_id)->where ('status','in',[3,4])->group ('maintenance_user_id')->select ()->toArray ();
							$maintenance_user_ids = array_column($maintenance_user_ids,'maintenance_user_id');

							$count=count($maintenance_user_id);
							$counts=count($maintenance_user_ids);

							$ticheng = Db::name('worker_examine')->where ('order_id','in',$order_ids)->where ('user_id','in',$maintenance_user_id)->sum ('ticheng');
							$price = $ticheng/$count;
							$prices = $ticheng/($count+$counts);
							$price = $price - $prices;
							foreach ($maintenance_user_id as $v){
								Db::name('worker_examine')->insert( ['time'=>$date,
									'user_id'=>$v,
									'single_quantity'=>1,
									'performance'=>0,
									'Bad'=>$status,
									'esteem'=>$statuss,
									'substract'=>$price,
									'ticheng'=>0,
									'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
							}
							foreach ($maintenance_user_ids as $v){
								Db::name('worker_examine')->insert( ['time'=>$date,
									'user_id'=>$v,
									'single_quantity'=>1,
									'performance'=>$ticheng,
									'Bad'=>$status,
									'esteem'=>$statuss,
									'substract'=>0,
									'ticheng'=>$prices,
									'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
							}
						}
					}
				}
				Db::name('maintenance_order')->where('order_id',$order_id)->where ('status','in',[3,4])->update (['is_accomplish'=>2]);
				Db::name('maintenance_order')->where('order_id',$order_id)->update (['status'=>5]);
			Db::commit();

			return app('json')->successful('ok');

		}catch (\Exception $e){
			Db::rollBack();

			return app('json')->fail($e->getMessage());
		}
	}

	//自动
	public function day3_ok (StoreOrder $StoreOrder)
	{
		$time=time ()-259200;
		$date =date ('Y-m-d H:i:s',$time);
		$data =Db::name('maintenance_order')->where ('ok_time', '<',$date)->where ('status',4)->group ('order_id')->select();
		foreach ($data as $v){
			$this->maintenance_wenti_ok_zidong ($v['order_id']);
		}
	}


	public function maintenance_wenti_ok_zidong ($order_id,StoreOrder $StoreOrder)
	{
		Db::startTrans();
		try{
		$StoreOrder-> where ('order_id', $order_id) -> update (['is_wenti' => 2, 'status' => 2,'wenti_time'=>time()]);
		$order = $StoreOrder-> where ('order_id', $order_id)->find ();
		if ($order['maintenance_type']==2){
			$StoreOrder-> where ('order_id', $order['pid']) -> update (['is_zhibao' => 1]);
		}

		$date = date('Y-m', $order['add_time']);
		$dates = date('Y-m-d H:i:s', $order['add_time']);
		$dated = date('Y-m-d ', $order['add_time']);
		$maintenance =  Db::name('maintenance')->where ('order_id',$order_id)->find ();
		$status=0;
		$statuss=0;
		$tbj_Bad_prices=0;
		$performance = $maintenance['maintenance_price'];
		$tbj_ma_bili= Db::name ('config')->where ('key','tbj_ma_bili')->field ('value')->find ();
		$tbj_an_bili= Db::name ('config')->where ('key','tbj_an_bili')->field ('value')->find ();
		$maintenance_order = Db::name('maintenance_order')->where('order_id',$order_id)->where ('status','in',[3,4])->select ();
		if ($order['maintenance_type']!=2){
			$maintenance_count  = count ($maintenance_order);
			$prices =round($performance*$tbj_ma_bili['value']/$maintenance_count,2);

			$data =[];
			foreach ($maintenance_order as $v){
				$data[] = ['time'=>$date,
					'user_id'=>$v['maintenance_user_id'],
					'single_quantity'=>1,
					'performance'=>$performance,
					'Bad'=>$status,
					'esteem'=>$statuss,
					'substract'=>$tbj_Bad_prices,
					'ticheng'=>$prices,
					'times'=>$dates,
					'timed'=>$dated,
					'order_id'=>$order_id];
			}
			Db::name('worker_examine')->insertAll($data);
			Db::name('worker_examine')->insert( ['time'=>$date,
				'user_id'=>$order['survey_user_id'],
				'single_quantity'=>1,
				'performance'=>$performance,
				'Bad'=>$status,
				'esteem'=>$statuss,
				'substract'=>$tbj_Bad_prices,
				'ticheng'=>round($performance*$tbj_an_bili['value'],2),
				'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);

		}else{
			$orders =$StoreOrder-> where ('id', $order['pid'])->field ('order_id') ->find ();
			$orderss =$StoreOrder-> where ('pid', $order['pid'])->where ('order_id','<>',$order_id) ->field ('order_id')->find ();
			if (empty($orderss)){

				$maintenance_user_id = Db::name('maintenance_order')->where ('order_id',$orders['order_id'])->where ('is_accomplish',2)->group ('maintenance_user_id')->field ('maintenance_user_id')->select ();
				$maintenance_user_ids = Db::name('maintenance_order')->where('order_id',$order_id)->where ('status','in',[3,4])->group ('maintenance_user_id')->field ('maintenance_user_id')->select ();

				$count=count($maintenance_user_id);
				$counts=count($maintenance_user_ids);

				$ticheng = Db::name('worker_examine')->where ('order_id',$orders['order_id'])->where ('user_id','in',$maintenance_user_id)->sum ('ticheng');
				$price = $ticheng/$count;
				$prices = $ticheng/($count+$counts);
				$price = $price - $prices;
				foreach ($maintenance_user_id as $v){
					Db::name('worker_examine')->insert( ['time'=>$date,
						'user_id'=>$v['maintenance_user_id'],
						'single_quantity'=>1,
						'performance'=>0,
						'Bad'=>$status,
						'esteem'=>$statuss,
						'substract'=>$price,
						'ticheng'=>0,
						'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
				}
				foreach ($maintenance_user_ids as $v){
					Db::name('worker_examine')->insert( ['time'=>$date,
						'user_id'=>$v['maintenance_user_id'],
						'single_quantity'=>1,
						'performance'=>$ticheng,
						'Bad'=>$status,
						'esteem'=>$statuss,
						'substract'=>0,
						'ticheng'=>$prices,
						'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
				}
			}else{
				$order_ids=array_column($orderss,'order_id');
				$order_ids[]=$orders['order_id'];

				$maintenance_user_id = Db::name('maintenance_order')->where ('order_id','in',$order_ids['order_id'])->where ('is_accomplish',2)->group ('maintenance_user_id')->field ('maintenance_user_id')->select ();
				$maintenance_user_ids = Db::name('maintenance_order')->where('order_id',$order_id)->where ('status','in',[3,4])->group ('maintenance_user_id')->field ('maintenance_user_id')->select ();

				$count=count($maintenance_user_id);
				$counts=count($maintenance_user_ids);

				$ticheng = Db::name('worker_examine')->where ('order_id','in',$order_ids['order_id'])->where ('user_id','in',$maintenance_user_id)->sum ('ticheng');
				$price = $ticheng/$count;
				$prices = $ticheng/($count+$counts);
				$price = $price - $prices;
				foreach ($maintenance_user_id as $v){
					Db::name('worker_examine')->insert( ['time'=>$date,
						'user_id'=>$v['maintenance_user_id'],
						'single_quantity'=>1,
						'performance'=>0,
						'Bad'=>$status,
						'esteem'=>$statuss,
						'substract'=>$price,
						'ticheng'=>0,
						'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
				}
				foreach ($maintenance_user_ids as $v){
					Db::name('worker_examine')->insert( ['time'=>$date,
						'user_id'=>$v['maintenance_user_id'],
						'single_quantity'=>1,
						'performance'=>$ticheng,
						'Bad'=>$status,
						'esteem'=>$statuss,
						'substract'=>0,
						'ticheng'=>$prices,
						'times'=>$dates,'timed'=>$dated,'order_id'=>$order_id]);
				}
			}

		}
		Db::name('maintenance_order')->where('order_id',$order_id)->where ('status','in',[3,4])->update (['is_accomplish'=>2]);
		Db::name('maintenance_order')->where('order_id',$order_id)->update (['status'=>5]);

		return app('json')->successful('ok');

		}catch (\Exception $e){
			Db::rollBack();
			return app('json')->fail($e->getMessage());
		}
	}

	//用户一键质保
	public function maintenance_wenti_assurance (StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$StoreOrder-> where ('order_id', $order_id) -> update (['is_zhibao' => 2]);
		return app('json')->successful('ok');
	}
	//获取维修工的数据
	public  function authority_list(Request $request, StoreOrder $StoreOrder)
	{
		[$time,$type]= $request->postMore([
			['time', ''],
			['type', 1],//订单状态
		], true);
		$time[0]  =date('Y-m-d H:i:s',time ());
		$time[1]  =date('Y-m-d H:i:s',time ()+3600);

		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$order = Db::name('maintenance_order')
			->whereOr(function($query)use ($time){
				$query->wheretime('service_times','>',$time[0]);
				$query->wheretime('service_times','<',$time[1]);
				$query->where('status','<',4);
			})
			->whereOr(function($query)use ($time){
				$query->wheretime('service_timess','>',$time[0]);
				$query->wheretime('service_timess','<',$time[1]);
				$query->where('status','<',4);
			})
			->whereOr(function($query)use ($time){
				$query->wheretime('service_times','<=',$time[0]);
				$query->wheretime('service_timess','>=',$time[1]);
				$query->where('status','<',4);
			})
			->group ('maintenance_user_id')->field ('maintenance_user_id')->select ()->toArray ();

		$data=Db::name('repair_service')
			->where('status',1)
			->where('is_del',0)
			->where('type',$type)
			->page ($page,$limit)
			->select()->toArray();
		foreach ($data as &$v){
			$v['order_status']='离线';
			foreach ($order as $k1=>$v1){
				if($v1['maintenance_user_id']==$v['uid']) $v['order_status']='在忙';
			}
			if ($v['status_work']==2) $v['order_status']='离线';
			if ($v['status_work']==1) $v['order_status']='空闲';

		}

		return app('json')->success($data);
	}
	// 我的快修质保
	public function maintenance_assurance_list(Request $request, StoreOrder $StoreOrder)
	{
		$page = input ('page', 1);
		$limit = input ('limit', 10);

		$time = time () - 2592000;
		[$user]= $request->postMore([
			['uid', ''],
		], true);
		$data = $StoreOrder->with ('maintenance')-> where ('type', 99) -> where ('status', '>=',2)-> where ('is_wenti', 2)-> where ('paid', 1) -> where ('uid', $user) -> where ('wenti_time', '>=', $time) -> where ('maintenance_type', '=', 1) ->order('wenti_time','desc')->page ($page,$limit)-> select ()->toArray ();
		foreach ($data as &$v){
			$v['wenti_time'] = date('Y-m-d H:i:s',$v['wenti_time']);
		}
		return app('json')->success($data);
	}
	// 我的装修质保
	public function decorate_assurance_list(Request $request, StoreOrder $StoreOrder)
	{
		$page = input ('page', 1);
		$limit = input ('limit', 10);
		[$user]= $request->postMore([
			['uid', ''],
		], true);
		$data = Db::name('construction')->where ('uid',$user)->where ('status',1)->where ('delete_time',null)-> select ()->toArray ();
		foreach ($data as &$v){
			$cat =Db::name('repair_cat')->where ('id','in',$v['cat'])->select ()->toArray ();
			$pid = array_column($cat,'pid');

            $v['cat_name'] = Db::name('repair_cat')->where ('id','in',$pid)->select ()->toArray ();
			foreach ($v['cat_name'] as &$vv){

				$vv['data_order'] = $StoreOrder->where ('cat_id',$vv['id'])->where ('uid',$user)
					->where ('status','>=',2)
					->where ('is_del',0)
					->where ('construction_id','=',$v['id'])
					->where ('maintenance_type',3)->with ('maintenance')->select ()->toArray ();


				$vv['status'] = $StoreOrder->where ('cat_id',$vv['id'])->where ('uid',$user)
					->where ('status','<',2)
					->where ('is_del',0)
					->where ('construction_id','=',$v['id'])
					->where ('maintenance_type',3)->select ()->toArray ();
			}
		}
		return app('json')->success($data);
	}
	//维修评价
	public function repaircomment (Request $request, StoreOrder $StoreOrder)
	{
		[$order_id,$content,$status,$nameless]= $request->postMore([
			['order_id', ''],//订单状态
			['content', ''],//订单状态
			['status', ''],//订单状态
			['nameless', ''],//匿名
		], true);
		$StoreOrder->where('order_id',$order_id)->update(['content'=> $content,'comment_time'=>time(),'comment_status'=>$status,'status'=>3,'nameless'=>$nameless]);

		$oreder  =$StoreOrder->where('order_id',$order_id)->find()->toArray ();


		if ( $status ==2){
			//添加违规记录
			$violation =Db::name('violation_record')->where ('order_id',$order_id)->where ('name','维修差评')->select ()->toArray ();
			if (!$violation){
				$data= [];
				$data['order_id']= $order_id;
				$data['fine']= 50;
				$data['work_category']= 1;
				$data['uid']= $oreder['survey_user_id'];
				$data['name']= '维修差评';
				$this->add_violati($data);
				$maintenance_order = Db::name('maintenance_order')->where ('order_id',$order_id)->where ('status','>=',4)->select ()->toArray ();
				foreach ($maintenance_order as $v){
					$data['order_id']= $order_id;
					$data['fine']= 50;
					$data['work_category']= 2;
					$data['uid']= $v['maintenance_user_id'];
					$data['name']= '维修差评';
					$this->add_violati($data);
				}
			}
		}
		return app('json')->successful('ok');

	}
	//添加违规
	public  function add_violati($data){
		$violati =array ();
		$violati['order_id'] = $data['order_id'];
		$violati['fine'] = $data['fine']??'';
		$violati['work_category'] = $data['work_category'];
		$violati['uid'] = $data['uid'];
		$violati['name'] = $data['name']??'';
		$violati['duration'] = $data['duration']??'';
		$violati['violation_time'] = date('Y-m-d H:i:s');
		Db::name('violation_record')->insert ($violati);
		$date = date('Y-m');
		$dates = date('Y-m-d H:i:s');
		$dated = date('Y-m-d ');
		Db::name('worker_examine')->insert(['time'=>$date,
			'user_id'=> $data['uid'],
			'single_quantity'=>1,
			'performance'=>0,
			'Bad'=>$violati['name']=='维修差评'?1:0,
			'esteem'=>0,
			'substract'=>$violati['fine'],
			'ticheng'=>0,'times'=>$dates,'timed'=>$dated,'order_id'=>$data['order_id']]);
	}

	//勘察员上门
	public function user_survey_call (Request $request, StoreOrder $StoreOrder)
	{
		$order_id = input ('order_id');
		$img = input ('img');
		$time = date('Y-m-d H:i:s');
		$StoreOrder->where ('order_id', $order_id)->update(['shangmen_img' =>$img,'shangmen_time'=>$time,'is_survey_shangmen' =>2]);
		return app('json')->success('ok',[$time]);
	}

	//勘察员   列表
	public  function list_surveyor (Request $request,StoreOrder $StoreOrder)
	{
		$where = $request->postMore([
			['status', ''],//订单类型

		]);

		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$where['uid'] = $request->uid();
		$field = ['*'];
		$list =$StoreOrder->alias ('o')->with ('maintenance')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('survey_user_id', $where['uid']);
			$query->where('is_system_del',0);
			$query->where('is_del',0);

			if ($where['status']== -1){//带报价
				$query->where('status','<=',0);
				$query->where('is_send',1);
				$query->where('is_chargeback',1);
				$query->where('paid',0);

			}
			if ($where['status']== -2){//勘查单
				$query->where('paid',0);
				$query->where('is_send',2);
				$query->where('is_del',0);
				$query->where('is_chargeback',1);
			}
			if ($where['status']== -3){//已派单
				$query->where('status','>=',0);
				$query->where('status','<=',2);
				$query->where('weixiu_status', 2);
				$query->where('is_chargeback',1);
				$query->where('paid',1);
				$query->where('is_wenti','<',2);
			}
			if ($where['status']== -4){//已退
				$query->where('is_chargeback', 2);
			}

			if ($where['status']== -5){//超时
				$query->where('is_repair_survey',2);
				$query->where('is_wenti','<',2);
			}
		})->page ($page,$limit)->field ($field)
			->select ()->toArray ();
		$count =$StoreOrder->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('survey_user_id', $where['uid']);
			$query->where('is_system_del',0);
			$query->where('is_del',0);

			if ($where['status']== -1){//带报价
				$query->where('status','<=',0);
				$query->where('is_send',1);
				$query->where('is_chargeback',1);
				$query->where('paid',0);

			}
			if ($where['status']== -2){//勘查单
				$query->where('paid',0);
				$query->where('is_send',2);
				$query->where('is_del',0);
				$query->where('is_chargeback',1);
			}
			if ($where['status']== -3){//已派单
				$query->where('status','>=',0);
				$query->where('status','<=',2);
				$query->where('weixiu_status', 2);
				$query->where('is_chargeback',1);
				$query->where('paid',1);
				$query->where('is_wenti','<',2);

			}
			if ($where['status']== -4){//已退
				$query->where('is_chargeback', 2);
			}

			if ($where['status']== -5){//超时
				$query->where('is_repair_survey',2);
				$query->where('is_wenti','<',2);

			}
		})->count();

		if ($where['status'] == -3) {//已派单
			$list = $this->chuli4($list);
		}else{
			$list = $this->chuli1($list);
		}
		return app('json')->successful('ok',compact('count', 'list'));
	}
	public  function list_surveyor_count (Request $request,StoreOrder $StoreOrder)
	{

		$where['uid'] = $request->uid();
		$list1 =$StoreOrder->alias ('o')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('survey_user_id', $where['uid']);
			$query->where('is_system_del',0);
			$query->where('is_del',0);
			$query->where('status','<=',0);
			$query->where('is_send',1);
			$query->where('is_chargeback',1);
			$query->where('paid',0);
		})->count ();
		$list2 =$StoreOrder->alias ('o')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('survey_user_id', $where['uid']);
			$query->where('is_system_del',0);
			$query->where('is_del',0);

				$query->where('paid',0);
				$query->where('is_send',2);
				$query->where('is_del',0);
				$query->where('is_chargeback',1);
		})->count ();
		$list3 =$StoreOrder->alias ('o')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('survey_user_id', $where['uid']);
			$query->where('is_system_del',0);
			$query->where('is_del',0);

				$query->where('status','>=',0);
				$query->where('status','<=',2);
				$query->where('weixiu_status', 2);
				$query->where('is_chargeback',1);
				$query->where('paid',1);
				$query->where('is_wenti','<',2);
		})->count  ();
		$list4 =$StoreOrder->alias ('o')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('survey_user_id', $where['uid']);
			$query->where('is_system_del',0);
			$query->where('is_del',0);
			$query->where('is_chargeback', 2);
		})->count  ();
		$list5 =$StoreOrder->alias ('o')->where (function ($query) use ($where) {
			$query->where('type', 99);
			$query->where('survey_user_id', $where['uid']);
			$query->where('is_system_del',0);
			$query->where('is_del',0);
			$query->where('is_repair_survey',2);
			$query->where('is_wenti','<',2);
		})->count  ();
		return app('json')->successful('ok',['count'=>$list1,'count2'=>$list2,'count3'=>$list3,'count4'=>$list4,'count5'=>$list5,]);
	}
	public function chuli2 ($list)
	{
		$StoreOrder = new StoreOrder;
		foreach ($list as $k => &$v) {
			if ($v['paid'] == 1) {
				if ($v['weixiu_status'] == 2) {

					if ($v['mstatus']==1){
						if (date('Y-m-d H:i:s', (time()+1800))>=$v['service_times']  && date('Y-m-d H:i:s')<$v['service_times']){
							$v['sur_time']=(strtotime($v['service_times'])-time())/60 >=30?'30':(strtotime($v['service_times'])-time())/60;
							$v['sur_title']='等待接单';
						}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['service_times']  && date('Y-m-d H:i:s')>$v['service_times']){
							$v['sur_time']=(time()-strtotime( $v['service_times']))/60>=1?(time()-strtotime( $v['service_times']))/60:'1'; //接单超时倒计时
							$v['sur_title']='已超时';
							if ($v['is_accept_status']!=2){
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
								Db::name('maintenance_order')->where ('order_id', $v['order_id'])->where ('maintenance_user_id', $v['maintenance_user_id'])->update(['is_accept_status'=>2]);
								$data['order_id']= $v['order_id'];
								$data['fine']= 10;
								$data['work_category']= 2;
								$data['uid']=$v['maintenance_user_id'];
								$data['name']= '接单超时';
								$data['duration']= $v['sur_time'];
								$this->add_violati($data);
							}
						}
					}elseif ($v['mstatus']==2){
						if (date('Y-m-d H:i:s', (time()+1800))>=$v['service_times']  && date('Y-m-d H:i:s')<$v['service_times']){
							$v['sur_time']=(strtotime($v['service_times'])-time())/60>=30?'30':(strtotime($v['service_times'])-time())/60;
							$v['sur_title']='等待维修';
						}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['service_times']  && date('Y-m-d H:i:s')>$v['service_times']){
							$v['sur_time']=(time()-strtotime( $v['service_times']))/60>=1?(time()-strtotime( $v['service_times']))/60:'1'; //上门超时倒计时
							$v['sur_title']='已超时';
							if ($v['is_shangmen_chaoshi']!=2){
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
								Db::name('maintenance_order')->where ('order_id', $v['order_id'])->where ('maintenance_user_id', $v['maintenance_user_id'])->update(['is_shangmen_chaoshi'=>2]);
								$data['order_id']= $v['order_id'];
								$data['fine']= 10;
								$data['work_category']= 2;
								$data['uid']=$v['maintenance_user_id'];
								$data['name']= '上门超时';
								$data['duration']= $v['sur_time'];
								$this->add_violati($data);
							}
						}
					}elseif ($v['mstatus']==3){
						if ($v['is_shangmen_chaoshi']==2){

							$times = strtotime ($v['service_timess'])-strtotime ($v['service_times'])+strtotime ($v['shangmentime']);

							if (date('Y-m-d H:i:s', (time()+1800))>=$times&&date('Y-m-d H:i:s')<$times){
								$timessss=strtotime($times)-time()/60;
								$v['sur_time']=$timessss>=30?'30':$timessss;  //勘察倒计时
								$v['sur_title']='时长剩余';  //勘察倒计时
							}elseif(time()+1800 >=$times&&time()>$times){

								$v['sur_time']=( time()-$times)/60>=1?(time()-$times)/60:'1';//维修超时
								$v['sur_title']='已超时';  //勘察倒计时
								if ($v['is_weixin_chaoshi']!=2){
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
									Db::name('maintenance_order')->where ('order_id', $v['order_id'])->where ('maintenance_user_id', $v['maintenance_user_id'])->update(['is_weixin_chaoshi'=>2]);
									$data['order_id']= $v['order_id'];
									$data['fine']= 10;
									$data['work_category']= 2;
									$data['uid']=$v['maintenance_user_id'];
									$data['name']= '维修超时';
									$data['duration']= $v['sur_time'];
									$this->add_violati($data);
								}
							}
						}else{
							if (date('Y-m-d H:i:s', (time()+1800))>=$v['service_times']  && date('Y-m-d H:i:s')<$v['service_times']){
								$v['sur_time']=(strtotime($v['service_times'])-time())/60>=30?'30':(strtotime($v['service_times'])-time())/60;
								$v['sur_title']='等待维修';
							}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['service_times']  && date('Y-m-d H:i:s')>$v['service_times']){
								$v['sur_time']=(time()-strtotime( $v['service_times']))/60>=1?(time()-strtotime( $v['service_times']))/60:'1'; //上门超时倒计时
								$v['sur_title']='已超时';
								if ($v['is_weixin_chaoshi']!=2){
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
									Db::name('maintenance_order')->where ('order_id', $v['order_id'])->where ('maintenance_user_id', $v['maintenance_user_id'])->update(['is_weixin_chaoshi'=>2]);
									$data['order_id']= $v['order_id'];
									$data['fine']= 10;
									$data['work_category']= 2;
									$data['uid']=$v['maintenance_user_id'];
									$data['name']= '维修超时';
									$data['duration']= $v['sur_time'];
									$this->add_violati($data);
								}
							}
						}
					}
				}
				if (isset($v['sur_time'])){
					$v['sur_time']=floor($v['sur_time']);

				}
			}
		}
		return $list ;
	}
	//处理数据
	public function chuli1 ($list)
	{
		$StoreOrder = new StoreOrder;

		foreach ($list as $k => &$v) {
			if ($v['paid'] == 0) {
				if ($v['weixiu_status'] === 1) {
					if ($v['is_send']==1&&$v['status']==-1){
						if (date('Y-m-d H:i:s', (time()+1800))>=$v['time']  && date('Y-m-d H:i:s')<$v['time']){
							$v['sur_time']=(strtotime($v['time'])-time())/60 >=30?'30':(strtotime($v['time'])-time())/60;
							$v['sur_title']='待报价';

						}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['time']  && date('Y-m-d H:i:s')>$v['time']){
							$v['sur_time']=(time()-strtotime( $v['time']))/60>=1?(time()-strtotime( $v['time']))/60:'1'; //待报价超时倒计时
							$v['sur_title']='已超时';   //已超时
							if ($v['is_quote']!=2){
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_quote'=>2]);
								$data['order_id']= $v['order_id'];
								$data['fine']= 10;
								$data['work_category']= 1;
								$data['uid']=$v['survey_user_id'];
								$data['name']= '报价超时';
								$data['duration']= $v['sur_time'];
								$this->add_violati($data);
							}
						}
					}
					if ($v['is_survey_shangmen']==1&&$v['survey_user_id_2']>0&&$v['is_send']==2){
						if (date('Y-m-d H:i:s', (time()+1800))>=$v['time']  && date('Y-m-d H:i:s')<$v['time']){

							$v['sur_time']=(strtotime($v['time'])-time())/60 >=30?'30':(strtotime($v['time'])-time())/60;
							$v['sur_title']='待上门';

						}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['time']  &&  date('Y-m-d H:i:s')>$v['time']){
							$v['sur_time']=(time()-strtotime( $v['time']))/60>=1?(time()-strtotime( $v['time']))/60:'1'; //上门超时倒计时
							$v['sur_title']='已超时';
							if ($v['is_timeout_survey_shangmen']!=2){
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
								$StoreOrder->where ('order_id', $v['order_id'])->update(['is_timeout_survey_shangmen'=>2]);
								$data['order_id']= $v['order_id'];
								$data['fine']= 10;
								$data['work_category']= 1;
								$data['uid']=$v['survey_user_id_2'];
								$data['name']= '上门超时';
								$data['duration']= $v['sur_time'];
								$this->add_violati($data);

							}
						}
					}elseif($v['is_survey_shangmen']==2&&$v['survey_user_id_2']!=null&&$v['is_send']==2&&$v['is_timeout_survey']==1){
						if ($v['is_timeout_survey_shangmen']==2){
							$times = strtotime ($v['times'])+(strtotime ($v['shangmen_time'])-strtotime ($v['time']));

							if (date('Y-m-d H:i:s', (time()+1800))>=$times&&time()<$times){
								$timessss=((time()+1800)-strtotime($times))/60;

								$v['sur_time']=$timessss>=1?$timessss:'1';  //勘察倒计时
								$v['sur_title']='勘察时长';  //勘察倒计时
							}elseif(date('Y-m-d H:i:s', (time()+1800))>=$times&& date('Y-m-d H:i:s')>$times){

								$v['sur_time']=strtotime( time()-$times)/60>=1?strtotime( time()-$times)/60:'1';//勘察超时正计时
								$v['sur_title']='已超时';  //勘察倒计时
								if ($v['is_timeout_survey']!=2){
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_timeout_survey'=>2]);
									$data['order_id']= $v['order_id'];
									$data['fine']= 10;
                                    $status = Db::name('repair_service')->where ('uid', $v['is_repair_survey'])->where ('status',1)->find();
                                    if ($status){
                                        $data['work_category']= 2;
                                    }else{
                                        $data['work_category']= 1;
                                    }
                                    $data['uid']=$v['survey_user_id_2'];
									$data['name']= '勘察超时';
									$data['duration']= $v['sur_time'];
									$this->add_violati($data);
								}

							}
						}else{
							if (date('Y-m-d H:i:s', (time()+1800))>=$v['times']  &&  date('Y-m-d H:i:s')<$v['times']){

								$v['sur_time']=(strtotime($v['time'])-time())/60 >=30?'30':(strtotime($v['time'])-time())/60;

								$v['sur_title']='勘察时长';  //勘察倒计时

							}elseif(date('Y-m-d H:i:s', (time()+1800))>=$v['times']  &&  date('Y-m-d H:i:s')>$v['times']){
								$v['sur_time']=(time()-strtotime( $v['time']))/60>=1?(time()-strtotime( $v['time']))/60:'1'; //勘察超时正计时
								$v['sur_title']='已超时';  //勘察倒计时
								if ($v['is_timeout_survey']!=2){
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_repair_survey' => 2]);
									$StoreOrder->where ('order_id', $v['order_id'])->update(['is_timeout_survey'=>2]);
									$data['order_id']= $v['order_id'];
									$data['fine']= 10;

                                    $status = Db::name('repair_service')->where ('uid', $v['is_repair_survey'])->where ('status',1)->find();
                                    if ($status){
                                        $data['work_category']= 2;
                                    }else{
                                        $data['work_category']= 1;
                                    }
                                    $data['uid']=$v['survey_user_id_2'];
									$data['name']= '勘察超时';
									$data['duration']= $v['sur_time'];
									$this->add_violati($data);
								}
							}
						}
					}

				}
			}
			if (isset($v['sur_time'])){
				$v['sur_time']=floor($v['sur_time']);
			}
		}
		return $list ;
	}

	//勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察 勘察




	//勘察  创建 支付订单
	public function user_repair_create(Request $request, StoreOrder $StoreOrder){


		$order_id = input ('order_id');
		$data[ 'files_user_surveyor' ] = input ('surveyor_img'); //维修照片
		$data[ 'maintenance_content' ] = input ('maintenance_content'); //维修内容
		$data[ 'notes' ] = input ('notes'); //备注
		$data[ 'tool' ] = input ('tool'); //工具清单
		$data[ 'material' ] = input ('material'); //用户购买的商品
		$data[ 'auxiliary_material_price' ] = input ('auxiliary_material_price'); //百街代购总价
		$data[ 'maintenance_price' ] =  input ('maintenance_price'); //工人价格
		$data[ 'auxiliary_material_data' ] = input ('auxiliary_material_data'); //百街代购数据
		$data[ 'peisong_price' ] = input ('peisong_price'); //百街配送费用
		$datas=input ('auxiliary_material_data');
		if (!$order_id) {
			return app('json')->fail('未找到此单!');
		}
		if (!$data[ 'maintenance_content' ]){
			return app('json')->fail('维修项目不能为空');
		}
		if (!input ('yvyue_maintenance_time')){
			return app('json')->fail('维修时间不能为空');
		}
		if (!is_numeric($data[ 'maintenance_price' ])){
			return app('json')->fail('工人价格不能提交其他数据');

		}	if (!is_numeric($data[ 'auxiliary_material_price' ])){
			return app('json')->fail('百街代购总价不能提交其他数据');

		}if (!is_numeric($data[ 'peisong_price' ])){
			return app('json')->fail('百街配送费用不能提交其他数据');

		}
		$data['auxiliary_material_price'] =$data['auxiliary_material_price']>0?$data['auxiliary_material_price']:0;
		$data['maintenance_price'] = $data['maintenance_price']>0?$data['maintenance_price']:0;
		$data[ 'peisong_price' ] = $data[ 'peisong_price' ]>0?$data[ 'peisong_price' ]:0;
		$price = $data['auxiliary_material_price']+$data['maintenance_price']+$data[ 'peisong_price' ];

		Db::startTrans();
		try {
			$order_give_integral = sys_config('order_give_integral');

			$order=[];
			$order['total_price']=$price;
			$order['pay_price']=$price;
			$order['give_integral']= bcmul((string)$order_give_integral,$price, 0);
			$order['weixiu_status']=2;
			$order['status']=0;
			if (input ('maintenance_type')==1){
				if ($price==0){
					Db::rollback();
					return app('json')->fail('快修订单人工费不能0元提交');
				}
			}
			if (!empty($datas['material'])){
				foreach (json_decode ($datas,true) as $k=>$v){
					Db::name('auxiliary_material_data')->insert (['order_id'=>$order_id,'material'=>$v['material'],'price'=>$v['price'],'nums'=>$v['nums']]);
				}
			}

			$maintenance_user_id = input ('maintenance_user_id');//工人id
			$maintenance_user_id  =explode(',',$maintenance_user_id);
			if (!empty(input ('yvyue_maintenance_time'))){
				$yvyue_time  =explode(',',input ('yvyue_maintenance_time'));
			}
			if (strtotime($yvyue_time[0]) <= time ()+1800){
				return app('json')->fail('快修时间选择错误');
			}
			foreach ($maintenance_user_id as $k=>$v){
				$maintenance_order['service_times'] =$yvyue_time[0];
				$maintenance_order['service_timess'] =$yvyue_time[1];
				$maintenance_order['order_id'] =$order_id;
				$maintenance_order['maintenance_user_id'] =$v;
				Db::name('maintenance_order')->insert($maintenance_order);
			}
			$order['maintenance_type'] = input ('maintenance_type');//1  =室内快修   2快修质保   3装修质保
			if ($order['maintenance_type']==1){
				if ($price==0){
					Db::rollback();
					return app('json')->fail('快修订单人工费不能0元提交');
				}
			}
			$data['maintenance_type'] = input ('maintenance_type'); //1  =室内快修   2快修质保   3装修质保

			$order_index = $StoreOrder->where('order_id', $order_id)->find ();
			if ($order_index['is_chargeback']==1){
				if ( input ('maintenance_type')>=2){
					$order['paid'] =1;
				}else{
					$order['paid'] =0;
				}
			}
			$order[ 'service_times' ] =$yvyue_time[0];
			$order[ 'service_timess' ] = date('m-d H:i',strtotime($yvyue_time[1]));
			$order['create_times']=date('Y-m-d H:i:s');
			$order['is_chargeback']=1;
			$StoreOrder->where('order_id', $order_id)->update($order);

			$data['order_id'] =$order_id;
			Db::name('maintenance')->where('order_id', $order_id)->delete();

			Db::name('maintenance')->insert($data);
			Db::commit();
		} catch (\Exception $e) {
			Db::rollback();
			return app('json')->fail( $e->getMessage());
		}
		return app('json')->success('ok');
	}

	public function survey_list (Request $request, StoreOrder $StoreOrder)
	{

	}

	//勘察员转派给自己或者别人
	public function survey_user_add(Request $request, StoreOrder $StoreOrder)
	{

		$res  = $request->postMore([
			['uid', 1],//id
			['time', ''],//id
			['order_id', '']//订单类型
		]);
		$time  =explode(',',input ('time'));

		if (strtotime($time[0]) <= time ()+1800){
			return app('json')->fail('时间选择错误');
		}
		$order=$StoreOrder->where ('order_id', $res['order_id'])->find ();
		if ($order['is_send']==2||$order['weixiu_status']==2){
			return app('json')->fail('当前订单已转派，或已经报价完成');
		}
		$StoreOrder->where ('order_id', $res['order_id'])->update(['survey_user_id_2' => $res['uid'],'is_send'=>2,'time'=>$time[0],'times'=>$time[1],'is_chargeback'=>1]);
		return app('json')->successful('ok');
	}

	public function get_survey_jilu (Request $request, StoreOrder $StoreOrder)
	{
		$page = input ('page', 1);
		$limit = input ('limit', 10);
		$where['uid']=$request->uid ();
		$list=$StoreOrder->with ('maintenance')->where (function ($query) use ($where) {
			$query -> where ('type', 99);
			$query -> where ('survey_user_id', $where[ 'uid' ]);
			$query -> where ('is_system_del', 0);
			$query -> where ('is_del', 0);
			$query->where('status', '>=',2);
			$query->where('is_wenti', '=',2);
		})->page ($page,$limit)->order ('wenti_time','desc')->select ();

		$count=$StoreOrder->where (function ($query) use ($where) {
			$query -> where ('type', 99);
			$query -> where ('survey_user_id', $where[ 'uid' ]);
			$query -> where ('is_system_del', 0);
			$query -> where ('is_del', 0);
			$query->where('status', '>=',2);
			$query->where('is_wenti', '=',2);
		})->count ();
		return app('json')->successful('ok',compact('count', 'list'));

	}

	//超时 ////////////////////////超时
	public function chaoshi  (Request $request, StoreOrder $StoreOrder)
	{
		[$order_id,$status,$time]= $request->postMore([
			['order_id', ''],
			['status', 1],//订单状态
			['time', 1],//订单状态
		], true);
		$order =$StoreOrder->where ('order_id', $order_id)->find ();
		$StoreOrder->where ('order_id', $order_id)->update(['is_repair_survey' => 2]);
		if ($status==1){//勘察上门超时
			$StoreOrder->where ('order_id', $order_id)->update(['is_timeout_survey_shangmen'=>2,'survey_shangmen_time'=>$time]);
			$data['order_id']= $order_id;
			$data['fine']= 10;
			$data['work_category']= 1;
			$data['uid']=$order['survey_user_id'];
			$data['name']= '上门超时';
			$data['duration']= $time;
			$this->add_violati($data);
		}
		if ($status==2){//勘察结束超时上门超时
			$data['order_id']= $order_id;
			$data['fine']= 10;
			$data['work_category']= 1;
			$data['uid']=$order['survey_user_id'];
			$data['name']= '勘察超时';
			$data['duration']= $time;
			$this->add_violati($data);
			$StoreOrder->where ('order_id', $order_id)->update(['is_timeout_survey'=>2,'timeout_survey_time'=>$time]);
		}
		if ($status==3){//维修工接单

			$data['order_id']= $order_id;
			$data['fine']= 10;
			$data['work_category']= 2;
			$data['uid']=$order['maintenance_user_id'];
			$data['name']= '接单超时';
			$data['duration']= $time;
			$this->add_violati($data);
			Db::name('maintenance_order')->where ('order_id', $order_id)->where ('maintenance_user_id', $request->uid ())->update(['is_accept_status'=>2,'accept_status_time'=>$time]);
		}
		if ($status==4){//维修工上门超时上门超时

			$data['order_id']= $order_id;
			$data['fine']= 10;
			$data['work_category']= 2;
			$data['uid']=$order['maintenance_user_id'];
			$data['name']= '上门超时';
			$data['duration']= $time;
			$this->add_violati($data);
			Db::name('maintenance_order')->where ('order_id', $order_id)->where ('maintenance_user_id', $request->uid ())->update(['is_shangmen_chaoshi'=>2,'shangmen_time'=>$time]);
		}
		if ($status==5){//维修工维修超时
			$data['order_id']= $order_id;
			$data['fine']= 10;
			$data['work_category']= 2;
			$data['uid']=$order['maintenance_user_id'];
			$data['name']= '维修超时';
			$data['duration']= $time;
			$this->add_violati($data);
			Db::name('maintenance_order')->where ('order_id', $order_id)->where ('maintenance_user_id', $request->uid ())->update(['is_weixin_chaoshi'=>2,'weixin_chaoshi_time'=>$time]);
		}
		return app('json')->successful('ok');

	}
	public	function surveyor_info  (Request $request)
	{
		$info =Db::name('surveyor_service')->where ('uid', $request->uid ())->where ('is_del',0)->where ('status',1)->find();
		if (!$info){
			return app('json')->fail ('为找到此信息');
		}
		return app('json')->successful('ok',$info);
	}

	public	function repair_info  (Request $request)
	{
		$info =Db::name('repair_service')->where ('uid', $request->uid ())->where ('is_del',0)->where ('status',1)->find();
		if (!$info){
			return app('json')->fail ('为找到此信息');
		}
		return app('json')->successful('ok',$info);
	}
	//员工上下班打卡
	public function add_work(request $request, StoreOrder $StoreOrder)
	{
		$work_type = input('work_type');
		$ship = input('ship','');
		$time = date('Y-m-d H:i:s');
		Db::name('repair_service')->where ('uid',$request->uid ())->update(['status_work' => $work_type]);
		Db::name('surveyor_service')->where ('uid',$request->uid ())->update(['status_work' => $work_type]);
		if ($work_type == 1) {
			$savedata = ['go_work_time' => $time,'go_ship'=>$ship];
		} elseif ('2') {
			$savedata = ['come_work_time' => $time,'come_ship'=>$ship];
		}
		$user_work = Db::name('user_work')
			->where('uid', $request->uid ())
			->where('time', date('Y-m-d'))
			->find();
		if ($user_work) {
			Db::name('user_work')
				->where('uid', $request->uid ())
				->where('time', date('Y-m-d'))
				->update($savedata);
		} else {
			if ($work_type == 1) {
				$savedata = ['go_work_time' => $time,'go_ship'=>$ship,'uid' =>$request->uid (), 'time' => date('Y-m-d')];
			} elseif ('2') {
				$savedata = ['come_work_time' => $time,'come_ship'=>$ship,'uid' =>$request->uid (), 'time' => date('Y-m-d')];
			}
			Db::name('user_work')->insert($savedata);
		}
		return app('json')->successful('ok',$savedata);

	}
	//工人绩效
	public function worker_user_info(request $request)
	{
		$time = input('time');
		if (!$time){
			$time = \date('Y-m');
		}
		$data['res'] = Db::name('worker_examine')->where('user_id', $request->uid ())->where('time', $time)
			->field('sum(single_quantity) as single_quantity,sum(performance) as performance, sum(Bad) as Bad,sum(esteem)  as esteem ,sum(substract)  as substract ,sum(settlement)  as settlement,sum(ticheng)  as ticheng ,time')
			->find();
		$single_quantity['res'] = Db::name('worker_examine')->where('user_id', $request->uid ())->where('time', $time)
			->group ('order_id')
			->count ();

		$data['res']['single_quantity']= $single_quantity['res']==null?0:$single_quantity['res'];
		$data['res']['performance']=$data['res']['performance']==null?0:$data['res']['performance'];
		$data['res']['Bad']=$data['res']['Bad']==null?0:$data['res']['Bad'];
		$data['res']['esteem']=$data['res']['esteem']==null?0:$data['res']['esteem'];
		$data['res']['substract']=$data['res']['substract']==null?0:$data['res']['substract'];
		$data['res']['settlement']=$data['res']['settlement']==null?0:$data['res']['settlement'];
		$data['res']['ticheng']=$data['res']['ticheng']==null?0:$data['res']['ticheng'];
		$data['res']['time']=$data['res']['time']==null?0:$data['res']['time'];

		return app('json')->successful('ok',$data);

	}
	//工人绩效
	public function worker_user_list(request $request)
	{
		$time = input('time');
		if (!$time){
			$time = \date('Y-m');
		}
		$data['list'] = Db::name('worker_examine')->where('user_id', $request->uid ())->where('time', $time)->where('substract|ticheng','>',0)
			->field('performance,  Bad, esteem , substract , settlement, ticheng ,time,order_id')->order ('created_at','desc')
			->select();

		$data['res'] = Db::name('worker_examine')->where('user_id', $request->uid ())->where('time', $time)
			->field('sum(single_quantity) as single_quantity,sum(performance) as performance, sum(Bad) as Bad,sum(esteem)  as esteem ,sum(substract)  as substract ,sum(settlement)  as settlement,sum(ticheng)  as ticheng ,time')
			->find();
		$single_quantity['res'] = Db::name('worker_examine')->where('user_id', $request->uid ())->where('time', $time)
			->group ('order_id')
			->field('sum(single_quantity) as single_quantity')
			->find();

		$data['res']['single_quantity']= isset($single_quantity['res']['single_quantity']) && !empty($single_quantity['res']['single_quantity'])?$single_quantity['res']['single_quantity']:0;
		$data['res']['performance']=$data['res']['performance']&&!empty($data['res']['performance'])?$data['res']['performance']:0;
		$data['res']['Bad']=isset($data['res']['Bad'])&&!empty($data['res']['Bad'])?$data['res']['Bad']:0;
		$data['res']['esteem']=isset($data['res']['esteem'])&&!empty($data['res']['esteem'])?$data['res']['esteem']:0;
		$data['res']['substract']=isset($data['res']['substract'])&&!empty($data['res']['substract'])?$data['res']['substract']:0;
		$data['res']['settlement']=isset($data['res']['settlement'])&&!empty($data['res']['settlement'])?$data['res']['settlement']:0;
		$data['res']['ticheng']=isset($data['res']['ticheng'])&&!empty($data['res']['ticheng'])?$data['res']['ticheng']:0;
		$data['res']['time']=isset($data['res']['time'])&&!empty($data['res']['time'])?$data['res']['time']:0;


		return app('json')->successful('ok',$data);

	}

	public  function get_work_list(request $request){
		$ctime = input('ctime');
		$stime = input('stime');
		$data =Db::name('user_work')->where('uid',$request->uid ())->whereTime('time','between',[$ctime,$stime])->select()->toArray ();
		return app('json')->successful('ok',$data);
	}

	public  function get_violati_list(request $request){

		$ctime = input('ctime');
		$stime = input('stime');
		$type = input('type',1);
		$data =Db::name('violation_record')->alias ('v')->join ('eb_store_order a','v.order_id=a.order_id')->where('v.uid',$request->uid ())->where('v.work_category',$type)->whereTime('v.violation_time','between',[$ctime,$stime])->order ('v.id','desc')->field ('v.*,From_unixtime(a.wenti_time,\'%Y-%m-%d %H:%i:%s\') as wenti_time,a.service_times,a.order_id,a.user_address')->select()->toArray ();

		return app('json')->successful('ok',$data);
	}
	public  function get_violati_count(request $request){

		$ctime = input('ctime');
		$stime = input('stime');
		$type = input('type',1);
		$data =Db::name('violation_record')->alias ('v')->join ('eb_store_order a','v.order_id=a.order_id')->where('v.uid',$request->uid ())->where('v.work_category',$type)->whereTime('v.violation_time','between',[$ctime,$stime])->count();

		return app('json')->successful('ok',['count'=>$data]);
	}
	//维修图片配置
	public  function weixin_deploy(){

		$data =Db::name('weixin_deploy')->select()->toArray ();
		return app('json')->successful('ok',$data);

	}

	//用户须知维修
	public  function weixin_notice(){

		$data = '请您在 5 分钟内完成支付，如此我们方能及时安排人员与准备材料，并在预约时间上门为您服务。倘若您未能于规定时间内完成支付，本次订单将会被取消，届时您可重新申请订单。';

		return app('json')->successful($data);
	}

	//获取维修项目
	public function get_two_cat_list(request $request)
	{
		$construction_id= input('construction_id');

		$id = $param["id"] ?? 0;
		$data = RepairCat::getApiRepairCatData($id, "");
		$construction = Db::name('construction')->where('id',$construction_id)->find();
		$cat = explode (',',$construction['cat']);
		foreach ($data[0]['children'] as  &$value){

			foreach ($value['children'] as$k=> &$item){

				foreach ($item['children'] as $kk=>$v){
					if (!in_array($v['id'],$cat)){
						unset($item['children'][$kk]);
					}
				}
				$item['children'] = array_values($item['children']);

			}
//			$value['children'] = array_values($value['children']);
		}

		return app('json')->successful('ok',$data);
	}

	public function get_con_index (request $request)
	{
		$id = input('id');
		$data=Db::name('construction')->where ('id',$id)->find ();
		return app('json')->successful('ok',$data);
	}
	public function get_construction(request $request, StoreOrder $StoreOrder)
	{
		[$cat_id]= $request->postMore([
			['cat_id', ''],//订单状态
		], true);
		$user_id =$request->uid ();

		$order =$StoreOrder->where('uid',$user_id)
			->where('is_del',0)
			->where('maintenance_type',3)
			->where('is_system_del',0)
			->where('cat_id',$cat_id)
			->where('status','<',2)
			->where('is_wenti',2)
			->select();
		if ($order){
			return app('json')->fail('ok');
		}else{
			return app('json')->success('ok');

		}

	}

	//cs
	public function examine_jvli ()
	{
		$data=input ('yx');
		//116.453557,39.932248
		$yx=explode(',',$data);
		if (empty($data) || count($yx) !== 2 || !is_numeric($yx[0]) || !is_numeric($yx[1])) {
			return app('json')->fail('Invalid coordinates');
		}
		$distance = $this->get_distance(['116.44751382426128','39.93181872525689'],$yx);
		if ($distance<=1500){
			return app('json')->successful($distance);
		}else{
			return app('json')->fail($distance);

		}
	}

	public function  get_distance($from,$to,$km=false,$decimal=2)
	{
		sort($from);
		sort($to);
		$EARTH_RADIUS = 6370.996; // 地球半径系数

		$distance = $EARTH_RADIUS * 2 * asin(sqrt(pow(sin(($from[0] * pi() / 180 - $to[0] * pi() / 180) / 2), 2) + cos($from[0] * pi() / 180) * cos($to[0] * pi() / 180) * pow(sin(($from[1] * pi() / 180 - $to[1] * pi() / 180) / 2), 2))) * 1000;

		if ($km) {
			$distance = $distance / 1000;
		}

		return round($distance, $decimal);
	}
	public function setAllRead (Request $request)
	{
		$uid =  $request->uid();
		/** @var StoreServiceRecordServices $StoreServiceRecordServices */
		$StoreServiceRecordServices = app()->make(StoreServiceRecordServices::class);
		$StoreServiceRecordServices->setAllRead($uid);
		return app('json')->success('设置成功');
	}

}




